package service.impl;

import dao.AddressDao;
import dao.impl.AddressDaoImpl;
import entity.Address;
import service.AddressService;

import java.util.List;

/**
 * @version 1.0
 * @Author: xxf
 * @CreateDate: 2020/10/7 17:04
 */
public class AddressServiceImpl implements AddressService {

    private AddressDao addressDao = new AddressDaoImpl();

    /**
     * 根据用户id获取收货地址信息集合
     * @param uid 用户uid
     * @return
     */
    @Override
    public List<Address> findAddressByUid(int uid) {
        return addressDao.findAddressByUid(uid);
    }

    /**
     * 保存用户收货地址
     * @param address
     */
    @Override
    public void saveAddress(Address address) {
        addressDao.addAddress(address);
    }

    /**
     * 删除用户收货地址
     * @param aid
     */
    @Override
    public void delAddressByAid(int aid) {
        addressDao.deleteAddressByAid(aid);
    }

    /**
     * 设置默认用户收货地址
     * @param aid
     * @param uid
     */
    @Override
    public void setAddressToDefault(int aid, int uid) {
        //将aid的astate改为1，其他改为0
        addressDao.updateAddressToDefaultByAid(aid);
        addressDao.updateAddressToCommonsByAid(aid,uid);
    }

    /**
     * 修改收货地址信息
     * @param address
     */
    @Override
    public void updateAddressByAid(Address address) {
        addressDao.updateAddressByAid(address);
    }
}
